package com.lixinxin.commoncomposeproject.network

import com.lixinxin.commoncomposeproject.model.ArticleModel
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

/**
 *   author ： lixinxin
 *   time    ： 2021-11-19
 *   email：895330766@qq.com
 */
object ApiClient {


    private val BASE_URL = "https://www.wanandroid.com"


    private val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()


    private val retrofit: Retrofit by lazy {

        Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .build()

    }

    val apiService: ApiService by lazy {
        retrofit.create(ApiService::class.java)
    }

}


interface ApiService {

    // 1.首页相关
    // 1.1首页文章列表
    @GET("article/list/{page}/json")
    suspend fun articleList(
        @Path("page") page: Int,
        @Query("page_size") page_size: Int = 20
    ): ArticleModel
}


